function insertSort(array) {
    for (let i = 1; i < array.length; i++) {
        let j = i
        let target = array[j]
        while (j > 0) {
            if (array[j - 1] > target) {
                array[j] = array[j - 1]
            } else {
                break
            }
            j--
        }
        array[j] = target

    }
    return array
}
let arr = [3, 6, 2, 4, 1]

console.log(insertSort(arr))